package fanjingzhu.check.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import publics.model.Application;
import publics.model.Enterprise;
import publics.util.Page;
import fanjingzhu.check.dao.ApplicationDao;
import fanjingzhu.check.service.ApplicationService;

@Component("applicationService")
public class ApplicationServiceImpl implements ApplicationService{
	
    private ApplicationDao applicationDao;
	
	
	public ApplicationDao getApplicationDao() {
		return applicationDao;
	}
    @Resource(name="applicationDao")
	public void setApplicationDao(ApplicationDao applicationDao) {
		this.applicationDao = applicationDao;
		System.out.println("applicationDaoImpl inject in ApplicationServiceImpl ");
	}
    //添加新的申请表
	public Object saveApplication(Application application) {
		return this.applicationDao.save(application);
	}
    //删除申请表
	public boolean deleteApplication(Integer applicationId) {
		return this.applicationDao.deleteById(applicationId);
	}
    //更新申请表
	public boolean updateApplication(Application application) throws Exception {
		return this.applicationDao.update(application);
	}
	
	//根据id查找特定的申请表
	public Application findById(Integer applicationId) {
		return applicationDao.findById(applicationId);	
	}
	
	//分页查找申请表
	public Page findByPage(Page page) {
		String sql = "from Application";
		System.out.println("sql ="+sql);// 测试用，请观察拼接出的sql语句，加强理解
		int pageSize = page.getLimit();
		int offset = page.getStart();//-1)*pageSize;
		page.setRoot(applicationDao.findByPage(sql,offset,pageSize));//把查询结果放入root中
		page.setTotalProperty(applicationDao.findByCount(sql));   //把数据总数放入totalProperty中
		return page;
	}
	
    //查找待初审的申请表
	public Page findByPageFirst(Page page) {
		String sql = "from Application a where a.state=1 ";
		System.out.println("sql ="+sql);// 测试用，请观察拼接出的sql语句，加强理解
		int pageSize = page.getLimit();
		int offset = page.getStart();//-1)*pageSize;
		page.setRoot(applicationDao.findByPage(sql,offset,pageSize));//把查询结果放入root中
		page.setTotalProperty(applicationDao.findByCount(sql));   //把数据总数放入totalProperty中
		return page;
	}
	
	//查找待复审的申请表
	public Page findByPageSecond(Page page) {
		String sql = "from Application a where a.state=2 ";
		System.out.println("sql ="+sql);// 测试用，请观察拼接出的sql语句，加强理解
		int pageSize = page.getLimit();
		int offset = page.getStart();//-1)*pageSize;
		page.setRoot(applicationDao.findByPage(sql,offset,pageSize));//把查询结果放入root中
		page.setTotalProperty(applicationDao.findByCount(sql));   //把数据总数放入totalProperty中
		return page;
	}
	
	//查找待终审的申请表
	public Page findByPageLast(Page page) {
		String sql = "from Application a where a.state=3 ";
		System.out.println("sql ="+sql);// 测试用，请观察拼接出的sql语句，加强理解
		int pageSize = page.getLimit();
		int offset = page.getStart();//-1)*pageSize;
		page.setRoot(applicationDao.findByPage(sql,offset,pageSize));//把查询结果放入root中
		page.setTotalProperty(applicationDao.findByCount(sql));   //把数据总数放入totalProperty中
		return page;
	}
	

}
